#include <stdio.h>

void initialize(int n, long long *a, int *t, int *e);

int main(void) {
	int n;
	scanf("%d", &n);
	long long admissionTicketNumber[n];
	int testSeatNumber[n];
	int examSeatNumber[n];
	initialize(n, admissionTicketNumber, testSeatNumber, examSeatNumber);
	int m;
	scanf("%d", &m);
	int searchTestSeatNumber = 0;
	for (int i = 0; i < m; i++) {
		scanf("%d", &searchTestSeatNumber);
		for (int j = 0; j < n; j++) {
			if (testSeatNumber[j] == searchTestSeatNumber) {
				printf("%lld %d\n", admissionTicketNumber[j], examSeatNumber[j]);
			}
		}
	}
}

void initialize(int n, long long *a, int *t, int *e) {
	for (int i = 0; i < n; i++) {
		scanf("%lld %d %d\n", &a[i], &t[i], &e[i]);
	}
}
